package com.demo.shardingsphere.supplier.config;


import com.demo.shardingsphere.util.OrderUtil;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * 分表路由
 */
public class SupplierTableAlgorithm implements PreciseShardingAlgorithm<Long> {


    /**
     * 商户id分表
     */
    @Override
    public String doSharding(Collection<String> availableTargetNames,
                             PreciseShardingValue<Long> shardingValue) {
        Long supplierId = shardingValue.getValue();
        Integer idSuffix= OrderUtil.getSuffixBySupplierId(supplierId);
        //分4张表
        String tableName= "t_supplier_order"+idSuffix%4;
        return tableName;
    }
}